var t, s;
$(document).ready(function() {
	showSmallBag(true);
	showMei()
});

function showSmallBag(a) {
	clearTimeout(s);
	t = setTimeout(function() {
		showSmallBagDelay(a)
	}, 500)
}

function showSmallBagDelay(b) {
	var a = $("#pop_up_shopping");
	var d = $("#countBank");
	var c = $("#contextPath").val();
	$.ajax({
		type: "POST",
		url: c + "/cart/small",
		data: {
			showCountAndAmount: b
		},
		success: function(h) {
			var g = h.count;
			d.html(g);
			if(!b) {
				var f = getBagHtml(h);
				$("#pop_up_shopping").html(f);
				a.stop().slideDown()
			} else {
				$("#shopping_quantity").text(h.count);
				$("#shopping_amount").text("¥" + h.amount)
			}
			var e = $(".my_product").size();
			if(e > 3) {
				loadScrollSmallBag("my_product_container")
			}
			s = setTimeout(function() {
				a.stop().slideUp()
			}, 3000)
		}
	})
}

function alwaysShow() {
	clearTimeout(s);
	$("#pop_up_shopping").show()
}

function hideSmallBag() {
	clearTimeout(t);
	clearTimeout(s);
	s = setTimeout(function() {
		$("#pop_up_shopping").stop().slideUp()
	}, 500)
}

function closeSmallBag(a) {
	$("#" + a).stop().slideUp(100)
}

function addProduct(d, a, b, f, e) {
	var i = 1;
	var h = 80;
	var c = "";
	var g = function(n, m, q, j, p) {
		var k = $.Deferred();
		var l = $("#contextPath").val();
		var o = addCart(l, n, m, q, j);
		switch(o.result) {
			case -1:
				i = -1;
				c = "商品库存不足！";
				break;
			case -2:
				i = -2;
				c = "您一次最多只能添加" + o.maxShopping + "件商品！";
				break;
			case -3:
				i = -3;
				c = "您一次最少必须添加" + o.minShopping + "件商品！";
				break;
			case -4:
				i = -4;
				c = "商品已售罄！";
				break;
			case -5:
				i = -5;
				c = "商品信息有误！";
				break;
			case -8:
				i = -8;
				c = "非常抱歉,活动无效！";
				break;
			case -9:
				i = -9;
				c = "非常抱歉,商品和活动不匹配！";
				break;
			case -10:
				i = -10;
				c = "非常抱歉,该商品已存在购物袋中！";
				break;
			case -15:
				i = -15;
				h = o.maxvalue;
				c = "抱歉，购物袋最多只能添加" + o.maxvalue + "个商品";
				break;
			case -16:
				i = -16;
				c = "本商品所在活动为VIP专场活动，升级为VIP之后才可以参与购买哦~会员升级规则请至魅力惠APP首页下方“我的” ——“会员规则”查看";
				if(o.msg != "") {
					c = o.msg
				}
				break;
			default:
				showSmallBag();
				break
		}
		k.resolve();
		return k.promise()
	};
	g(d, a, b, f, e);
	return {
		result: i,
		msg: c,
		maxvalue: h
	}
}

function delSamllBagProduct(b) {
	var a = $("#contextPath").val();
	$.ajax({
		type: "POST",
		url: a + "/cart/delete",
		data: {
			bagDetailId: b
		},
		success: function(c) {
			showSmallBag()
		}
	})
}

function getBagHtml(b) {
	var a = b.html;
	if(b.count != 0) {
		$("#shopping_quantity").text(b.count);
		$("#shopping_amount").text("¥" + b.amount)
	}
	return a
}

function getBankCount(c) {
	var b = 0;
	for(var a = 0; a < c.productList.length; a++) {
		b = b + c.productList[a].shoppingCount
	}
	return b
}

function loadScrollSmallBag(a) {
	$("." + a).jscroll({
		W: "3.5px",
		BgUrl: "",
		Bg: "right #e7e7e7 repeat-x",
		Bar: {
			Pos: "up",
			Bd: {
				Out: "#000 background-color #000",
				Hover: "#000 "
			},
			Bg: {
				Out: "-45px 0 repeat-x #000",
				Hover: "-58px 0 repeat-x  #000 pointer",
				Focus: "-71px 0 repeat-x  #000"
			}
		},
		Btn: {
			btn: false,
			uBg: {
				Out: "0 0 ",
				Hover: "-15px 0",
				Focus: "-30px 0"
			},
			dBg: {
				Out: "0 -15px",
				Hover: "-15px -15px",
				Focus: "-30px -15px"
			}
		},
		Fn: function() {}
	})
}
$(window).scroll(function() {
	var a = $(window).scrollTop();
	if(a >= 160) {
		$("#navBarId").removeClass();
		$("#navBarId").addClass("nav_container nav_container_top")
	} else {
		$("#navBarId").removeClass();
		$("#navBarId").addClass("nav_container")
	}
});

function toLogin() {
	goldlogRecord("/mei.3.1", "", "", "H1703600");
	var b = $("#contextPath").val();
	var c = document.location.href;
	c = base64encode(c);
	var a = b.split("//");
	if(typeof a[1] === "undefined") {
		host = ""
	} else {
		host = "http://" + a[1]
	}
	location.href = host + "/user/tologinpage?callbackUrl=" + c
}

function showMei() {
	$("#pup_mei").live("mouseover", function() {
		$(this).find(".pop_up_myGlamour").show()
	});
	$("#pup_mei").live("mouseout", function() {
		$(this).find(".pop_up_myGlamour").hide()
	});
	$("#pup_mei li:eq(0)").live("click", function() {
		window.location.href = $("#contextPath").val() + "/myMeiOrders/myOrderList"
	});
	$("#pup_mei li:eq(1)").live("click", function() {
		window.location.href = $("#contextPath").val() + "/myComment/myNotComment"
	});
	$("#pup_mei li:eq(2)").live("click", function() {
		window.location.href = $("#contextPath").val() + "/myConponsMessage/intomyconpons"
	});
	$("#pup_mei li:eq(3)").live("click", function() {
		window.location.href = $("#contextPath").val() + "/personInfo/showPersonInfo"
	});
	$("#pup_mei li:eq(4)").live("click", function() {
		window.location.href = $("#contextPath").val() + "/userAddress/userAddressshow"
	});
	$("#pup_mei li:eq(5)").live("click", function() {
		window.location.href = $("#contextPath").val() + "/personInfo/showPersonInfo"
	})
}

function clicksina() {
	var a = $("#contextPath").val();
	$.ajax({
		type: "POST",
		url: a + "/checkout/getShareWebsiteRecord",
		data: {
			websiteType: "1"
		},
		success: function(c) {
			var b = c.result
		}
	})
}

function shoppingSkipBag() {
	var a = $("#contextPath").val();
	var b = isLogins();
	if(b != null && b != "nologin") {
		location.href = a + "/cart"
	} else {
		var a = $("#contextPath").val();
		var c = document.location.href;
		c = base64encode(c);
		location.href = a + "/user/tologinpage?callbackUrl=" + c
	}
}

function illegalChar(b) {
	var a = /^([\u4E00-\u9FA5a-zA-Z0-9._-])*$/;
	if(a.test(b)) {
		return false
	} else {
		return true
	}
}

function goldlogRecord(a, d, c, b) {
	if(typeof(goldlog) == "object") {
		goldlog.record(a, d, c, b)
	}
};